
#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "EnemySpawner.generated.h"

UCLASS()
class XCZ2_API AEnemySpawner : public AActor
{
	GENERATED_BODY()
	
public:
	UPROPERTY(EditDefaultsOnly)
	TSubclassOf<class AEnemy2D> EnemyActorToSpawn;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float SpawnTime = 1.0f;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float SpawnDistance = 400.0f;

	UPROPERTY(VisibleAnywhere,BlueprintReadOnly)
	int TotalEnemyCount = 0;

	// 每击杀多少敌人增加难度
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	int DifficultySpawnInterval = 10;

	// 最小生成敌人间隔
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float SpawnTimeMinimumLimit = 0.5f;

	// 难度增加时，生成间隔减少的系数。
	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	float DecreaseSpawnTimeByEveryInterval = 0.05f;

	class ACharacter2D* Player;
	
	FTimerHandle SpawnTimer;

	
	AEnemySpawner();
	virtual void BeginPlay() override;
	virtual void Tick(float DeltaTime) override;

	void OnSpawnTimerTimeout();
	void StartSpawning();
	void StopSpawning();
	void SpawnEnemy();

	void SetupEnemy(AEnemy2D* Enemy);
};
